#pragma once
#include "2d/CCNode.h"
#include "base/ccTypes.h"
#include "ui/UIWidget.h"
#include "GLGlobalInfo.h"
#include <vector>
#include <functional>
#include "logicbase/GLContainerBase.h"
#include "logicbase/GLBaseDefine.h"
#include "common/PUtility.h"

#define NodeCOUNT	15

class CNodeContainerItemManager
{
public:
	struct ContainerItem {
		ContainerItem() : m_node(nullptr) {}
		cocos2d::Node*			m_node;
		GoodsInfo				m_goods;
		uint8_t					m_ContainerBox;
		uint8_t					m_ContainerIndex;
	};
	typedef std::vector<ContainerItem*>			VecItem_t;
#define ItemContentFlag_Side	BYTE_1
#define ItemContentFlag_Count	BYTE_2
#define ItemContentFlag_Back	BYTE_3
	struct ItemContent {
		void Clean() { m_ChangeFlag = 0; }
		void SetSide(const cocos2d::Color3B& color) { m_SideColor = color; CPUtility::Set1Byte<uint32_t>(m_ChangeFlag, ItemContentFlag_Side); }
		void SetCount(uint8_t count) { m_Count = m_Count; CPUtility::Set1Byte<uint32_t>(m_ChangeFlag, ItemContentFlag_Count); }
		void SetBack(const std::string& pic) { m_BackPic = pic; CPUtility::Set1Byte<uint32_t>(m_ChangeFlag, ItemContentFlag_Back); }
		uint32_t				m_ChangeFlag;
		cocos2d::Color3B		m_SideColor;
		uint8_t					m_Count;
		std::string				m_BackPic;
	};

	typedef std::function<void (cocos2d::Node* node, const ItemContent& content)>	FuncUpdateItem_t;
public:
	CNodeContainerItemManager(void);
	~CNodeContainerItemManager(void);

	void SetUpdateItemFunc(const FuncUpdateItem_t& func) { m_UpdateItem = func; }
	void SetContainer(CGLContainerBase* container) { m_Container = container; }
	void PushItem(cocos2d::Node* node);

	void UpdatePage(uint8_t box, uint8_t count = 1);
private:
	void onShowItemDetail(cocos2d::Ref* pSender, cocos2d::ui::TouchEventType type);
private:
	VecItem_t					m_Items;
	CGLContainerBase*			m_Container;
	FuncUpdateItem_t			m_UpdateItem;

	const GoodsInfo				m_TempInvalid;
	ItemContent					m_TempItemContent;
};
